

package com.hazelcast.client.impl.protocol.task;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.instance.impl.Node;
import com.hazelcast.internal.nio.Connection;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

/**
 * Base class for remove listener message tasks that removes a client listener registration
 * from a node
 *
 * @param <P> listener registration request parameters type
 */
public abstract class AbstractRemoveListenerMessageTask<P> extends AbstractAsyncMessageTask<P, Boolean> {

    protected AbstractRemoveListenerMessageTask(ClientMessage clientMessage, Node node, Connection connection) {
        super(clientMessage, node, connection);
    }

    @Override
    public final CompletableFuture<Boolean> processInternal() {
        endpoint.removeDestroyAction(getRegistrationId());
        return (CompletableFuture<Boolean>) deRegisterListener();
    }

    protected abstract Future<Boolean> deRegisterListener();

    protected abstract UUID getRegistrationId();

    @Override
    public Object[] getParameters() {
        return new Object[]{getRegistrationId()};
    }

}
